package com.atguigu.gulimall.gataway.CoreConfig;

import org.hibernate.validator.internal.metadata.raw.ConfigurationSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @version : 1.0
 * @Author: yangmingsong
 * @Date: 2021/4/6-04-06-18:23
 * @Description: guli-mail
 */
@Configuration
public class GulimallCorConfig {

    @Bean
    public CorsWebFilter GulimallCorConfig() {
        UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();

        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.setAllowCredentials(true);

        corsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration);
        CorsWebFilter corsWebFilter = new CorsWebFilter(corsConfigurationSource);
        return corsWebFilter;
    }

}
